﻿<extend name="Public:office" />
<block name="title"><title>成员管理</title></block>
<block name="header_styles">
    <style type="text/css">
        .main-wrapper .container {
            background-color: #ffffff;
        }

        .dropdown-menu {
            text-align: center;
        }
    </style>
</block>
<block name="main">
    <div class="tabs-wrapper">
        <include file="Team:menu" />
        <div class="tab-content">
            <div class="tab-pane active" style="min-height: 600px;">
                <eq name="applyquit" value="1"><div class="row"><div class="panel panel-heading"><span>你已申请离职，请等待管理层批复。</span></div></div></eq>
                <eq name="berevoked" value="1"><div class="row"><div class="panel panel-heading"><span>你已被辞退，3个自然日后将正式从团队退出。期间你可与管理层沟通。</span><a href="javascript:void(0);" class="acceptFire btn btn-default">接受辞退</a></div></div></eq>
                <div class="row">
                    <div class="col-xs-8">
                        <div class="panel panel-custom">
                            <div class="panel-heading">当前团队成员&nbsp;&nbsp;&nbsp;<strong>{$count}</strong> 人</div>
                            <table class="table table-striped">
                                <tr>
                                    <th>名称</th>
                                    <th>职位</th>
                                    <th>邮箱</th>
                                    <th class="text-center" style="width: 150px;">管理</th>
                                </tr>
                                <tr>
                                    <td>{$founder.nickname}</td>
                                    <td>团队创始人</td>
                                    <td>{$founder.email}</td>
                                    <td class="text-center">-</td>
                                </tr>
                                <volist name="list" id="vo">
                                    <tr>
                                        <td style="vertical-align: middle;">{$vo.uname}</td>
                                        <td style="vertical-align: middle;">{$vo.jname}</td>
                                        <td style="vertical-align: middle;">{$vo.email}</td>
                                        <td class="text-center" style="vertical-align: middle;">
                                            <if condition="$creater eq 1">
                                                <div class="dropdown">
                                                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">操作 <i class="fa fa-angle-down"></i></a>
                                                    <ul class="dropdown-menu">
                                                        <li><a href="javascript:void(0);" data-uid="{$vo.uid|default=0}" data-dleader="{$vo.dleader|default=0}" class="firemployee">辞退</a></li>
                                                    </ul>
                                                </div>
                                                <elseif condition="$fireauth eq 1" />
                                                <div class="dropdown">
                                                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">操作 <i class="fa fa-angle-down"></i></a>
                                                    <ul class="dropdown-menu">
                                                        <li><a href="javascript:void(0);" data-uid="{$vo.uid|default=0}" data-dleader="{$vo.dleader}">辞退</a></li>
                                                    </ul>
                                                </div>
                                                <elseif condition="$uid eq $vo['uid']" />
                                                <div class="dropdown">
                                                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">操作 <i class="fa fa-angle-down"></i></a>
                                                    <ul class="dropdown-menu">
                                                        <li><a href="javascript:void(0);" class="applyquit">申请离职</a></li>
                                                    </ul>
                                                </div>
                                                <else />
                                                <span>-</span>
                                            </if>
                                        </td>
                                    </tr>
                                </volist>

                            </table>
                        </div>
                        <if condition="$fireauth eq 1">
                            <div class="panel panel-custom">
                                <div class="panel-heading">
                                    <strong>被辞退的成员</strong> <span>(三天内可撤销辞退)</span>    &nbsp;<span>已退出成员，含主动离职和被辞退成员。</span>
                                </div>
                                <table class="table table-striped">
                                    <tr>
                                        <th>名称</th>
                                        <th>邮箱</th>
                                        <th class="text-center" style="width: 150px;">管理</th>
                                    </tr>
                                    <empty name="waits">
                                        <tr><td colspan="3" class="text-center">暂无记录</td></tr>
                                        <else />
                                        <volist name="waits" id="witem">
                                            <if condition="$witem.state eq 4">
                                                <tr>
                                                    <td>{$witem.nickname}</td>
                                                    <td>{$witem.email}</td>
                                                    <td class="text-center">
                                                        <a href="javascript:void(0);" class="revokeFire" data-uid="{$witem.uid|default=0}">撤销辞退</a>
                                                    </td>
                                                </tr>
                                            </if>
                                        </volist>
                                    </empty>
                                </table>
                            </div>
                        </if>

                        <div class="panel panel-custom">
                            <div class="panel-heading"><strong>申请管理</strong></div>
                            <table class="table table-striped">
                                <empty name="shenqing">
                                    <tr><td colspan="3" class="text-center">暂无申请记录</td></tr>
                                    <else />
                                    <volist name="shenqing" id="sqitem">
                                        <tr>
                                            <if condition="$sqitem.state eq 0">
                                                <td style="vertical-align: middle;">
                                                    <a href="{$sqitem.uid|genTalentURL}" class="text-success">{$sqitem.uname}</a>
                                                    &nbsp;申请<b>加入</b>[<span class="text-success">{$sqitem.jname}</span>]职位
                                                </td>
                                                <td style="width:120px;vertical-align: middle;">
                                                    <eq name="checkauth" value="1">
                                                        <a href="javascript:void(0);" data-id="{$sqitem.id}" class="button-accept btn btn-success btn-sm">同意</a>
                                                        <a href="javascript:void(0);" data-id="{$sqitem.id}" class="button-reject btn btn-danger btn-sm">拒绝</a>
                                                    </eq>
                                                </td>
                                            </if>
                                        </tr>
                                    </volist>
                                    <volist name="waits" id="witem">
                                        <if condition="$witem.state eq 5">
                                            <tr>
                                                <td style="vertical-align: middle;">
                                                    <span>[{$witem.jname}</span>-<a href="{$witem.uid|genTalentURL}"><span>{$witem.uname}</span></a>]申请<b>离职</b>
                                                </td>
                                                <td style="width:120px;vertical-align: middle;">
                                                    <eq name="checkauth" value="1">
                                                        <a href="javascript:void(0);" data-uid="{$witem.uid}" class="agreequit btn btn-success btn-sm">同意</a>
                                                        <a href="javascript:void(0);" data-uid="{$witem.uid}" class="rejectquit btn btn-danger btn-sm">拒绝</a>
                                                    </eq>
                                                </td>
                                            </tr>
                                        </if>
                                    </volist>
                                </empty>
                            </table>
                        </div>
                    </div>
                    <div class="col-xs-4">
                        <eq name="inviteauth" value="1">
                            <div class="panel panel-custom">
                                <div class="panel-heading" style="white-space: nowrap;">您还可以向站外人员发送Email邀请TA加入团队</div>
                                <div class="panel-body">
                                    <form id="formInvite" method="POST" action="">
                                        <div class="form-group">
                                            <label class="control-label">对方Email地址</label> <span data-valmsg-for="email" data-valmsg-replace="true"></span>
                                            <div>
                                                <input id="miEmail" name="email" type="text" data-val="true" maxlength="100" data-val-required="请填写对方Email地址" class="form-control" />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="control-label">邀请TA任职哪个职位？</label>
                                            <div class="row">
                                                <div class="col-xs-12">
                                                    <select id="miJob" name="miJob" class="form-control" data-val="true" data-val-required="请选择职位">
                                                        <empty name="jobs">
                                                            <option value="当前无可加入职位">当前无可加入职位</option>
                                                        <else />
                                                        <volist name="jobs" id="job">
                                                            <option value="{$job.id}">{$job.name}&nbsp;&nbsp;(剩余数量:{$job['num']-$job['datastate']})</option>
                                                        </volist>
                                                        </empty>
                                                    </select>
                                                    <span data-valmsg-for="miJob" data-valmsg-replace="true"></span>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="control-label">留言</label>
                                            <div>
                                                <textarea id="miContent" name="content" class="form-control" rows="8" maxlength="100" placeholder="想要对TA说点什么，100字以内。"></textarea>
                                            </div>
                                        </div>
                                        <div class="form-buttons">
                                            <button type="submit" class="btn btn-success" id="btnSendInvite">发送邀请</button>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </eq>
                    </div>
                </div>
            </div>
        </div>
    </div>
</block>
<block name="footer_scripts">
    <script type="text/javascript">
        require(["jquery", "modules/message", "kendoui/kendo.web.min"], function ($, boroshare) {
            $(function () {
                $(".button-accept").click(function () {
                    ctrlAjax($(this).data("id"), 2);
                });
                $(".button-reject").click(function () {
                    ctrlAjax($(this).data("id"), 3);
                });
                $(".applyquit").click(function () {
                    applyquit();
                });
                //辞退成员
                $(".firemployee").click(function () {
                    var uid = $(this).data("uid");
                    sendFire(uid);
                });
                //撤销辞退
                $(".revokeFire").click(function () {
                    var uid = $(this).data("uid");
                    revokeFire(uid);
                });

                $(".acceptFire").click(function () {
                    acceptFire();
                });

                $(".rejectquit").click(function () {
                    var uid = $(this).data("uid");
                    rejectquit(uid);
                });

                $(".agreequit").click(function () {
                    var uid = $(this).data("uid");
                    agreequit(uid);
                });
            });

            function ctrlAjax(id, type) {
                var url = "{:U('Team/ctrl_ajax')}";
                $.post(url, { id: id, type: type }, function (data) {
                    var vdata = eval(data);
                    if (vdata.success == 1) {
                        boroshare.alert({ content: '操作成功', sure: function () { window.location.reload(); } });
                    }
                    else {
                        boroshare.alert({ content: vdata.msg });
                    }
                }, 'json');

                return false;
            }

            //发送辞退请求
            function sendFire(uid) {
                var url = "{:U('Team/firemployee_ajax')}";
                $.post(url, { 'uid': uid }, function (data) {
                    var vdata = eval(data);
                    if (vdata.success == 1) {
                        boroshare.alert({ content: vdata.msg, sure: function () { window.location.reload(); } });
                    }
                    else {
                        boroshare.alert({ content: vdata.msg });
                    }
                    return false;
                }, 'json');
                boroshare.close();
            }

            //撤销辞退
            function revokeFire(uid) {
                var url = "{:U('Team/revokefire_ajax')}";
                $.post(url, { 'uid': uid }, function (data) {
                    var vdata = eval(data);
                    if (vdata.success == 1) {
                        boroshare.alert({ content: vdata.msg, sure: function () { window.location.reload(); } });
                    }
                    else {
                        boroshare.alert({ content: vdata.msg });
                    }
                    return false;
                }, 'json');
            }

            //接受辞退
            function acceptFire() {
                var url = "{:U('Team/acceptfire_ajax')}";
                $.post(url, {}, function (data) {
                    var vdata = eval(data);
                    if (vdata.success == 1) {
                        boroshare.alert({ content: vdata.msg, sure: function () { window.location.href = "{:U('Team/index')}"; } });
                    }
                    else {
                        boroshare.alert({ content: vdata.msg });
                    }
                    return false;
                }, 'json');
            }

            //申请离职
            function applyquit() {
                var url = "{:U('Team/applyquit_ajax')}";
                $.post(url, {}, function (data) {
                    var vdata = eval(data);
                    if (vdata.success == 1) {
                        window.location.reload();
                    }
                }, 'json');
            }

            //批准离职申请
            function agreequit(uid) {
                var url = "{:U('Team/agreequit_ajax')}";
                $.post(url, { 'uid': uid }, function (data) {
                    var vdata = eval(data);
                    if (vdata.success == 1) {

                    }
                    else {

                    }
                    boroshare.alert({ content: vdata.msg, sure: function () { window.location.reload(); } });
                    return false;
                }, 'json');
            }

            //拒绝离职申请
            function rejectquit(uid) {
                var url = "{:U('Team/rejectquit_ajax')}";
                $.post(url, { 'uid': uid }, function (data) {
                    var vdata = eval(data);
                    if (vdata.success == 1) {
                        boroshare.alert({ content: vdata.msg, sure: function () { window.location.reload(); } });
                    }
                    else {
                        boroshare.alert({ content: vdata.msg });
                    }

                    return false;
                }, 'json');
            }

            $(function () {
                //发送邮件邀请站外朋友
                $("#btnSendInvite").click(function () {
                    if (!$("#formInvite").valid()) {
                        return false;
                    }
                    var email = $('#miEmail').val();
                    var job = $('#miJob').find('option:selected').val();
                    var content = $('#miContent').val();

                    var url = "{:U('Team/mailInvite_ajax')}";

                    kendo.ui.progress($("#formInvite"), true);

                    $.post(url, { 'email': email, 'job': job, 'content': content }, function (data) {
                        kendo.ui.progress($("#formInvite"), false);
                        var vdata = eval(data);
                        boroshare.alert({ content: vdata.msg });
                        $("#formInvite").get(0).reset();
                    }, 'json');
                    return false;
                });
            });

        });
    </script>
</block>
